﻿using IMModel.Domain;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using IMModel.Domain.Common;
using System.Data.Linq;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using IMModel;

namespace IMTests
{
    /// <summary>
    /// Ииндексы по подразделам
    ///</summary>
    [TestClass()]
    public class GetSubRazdels
    {
        void WriteSubGrad(params string[] Sections)
        {
            using (var ctx = new IMDataDataContext("Data Source=ugtudb.ugtu.net;Initial Catalog=IndexMark;Integrated Security=True;MultipleActiveResultSets=True"))
            {
                var term = ctx.Terms.Single(x => x.IDTerm == 4);
                //var context = term.GetIndexContextDoctors();
                var context = term.GetIndexContextPPS();
                Console.WriteLine("ФИО;Должность;Факультет;Кафедра;" 
                    + string.Join(";'", Sections));
                //var i = term.CalcIndexes(context);

                var d = new Dictionary<string, RespondentIndexCollection>();
                foreach (var s in Sections)
                {
                    var st = term.SectionTerms.Single(x => x.Order == s);
                    d.Add(s, st.CalcIndexes(context));
                }

                var rr = term.SectionTerms.Single(x => x.Order == Sections[0])
                    .CalcIndexes(context);
                
                foreach (KeyValuePair<Respondent, double> v in rr.
                    OrderByDescending(x=>x.Value))
                {
                    var r = v.Key;
                    Console.Write(r.Person + ";"
                        + r.Job.Position.Name + ";"
                        + r.DepartmentTerm.DepartmentTerm1.Department.Abbriviation + ";"
                        + r.Department.Abbriviation + ";");
                    foreach (var k in d.Values)
	                {
		                Console.Write(k[r] * 1000 + ";");
	                }
                    Console.WriteLine();
                }
            }
        }
        
         /// <summary>
        /// отклонение докторов
        ///</summary>
        [TestMethod()]
        public void GetGrad()
        {
            // получение индексов по подразделам ИС
            WriteSubGrad("1", "1.1", "1.2", "1.2.1", "1.2.2", "2", "3", "3.1", "3.2", "4", "4.1", "4.2", "5", "5.1", "5.2", "5.3", "6", "6.1", "6.2");
            //WriteSubGrad("1", "1.1", "1.2", "1.2.1", "1.2.2");
            //WriteSubGrad("2");
            //WriteSubGrad("3", "3.1", "3.2");
            //WriteSubGrad("4", "4.1", "4.2");
            //WriteSubGrad("5", "5.1", "5.2", "5.3");
            //WriteSubGrad("6", "6.1", "6.2");
        }
    }
}